package com.xuyuan.spring.expand;

import com.xuyuan.spring.auto.AutoExample;
import com.xuyuan.spring.auto.AutoExample2;
import com.xuyuan.spring.auto.AutoExample3;
import com.xuyuan.spring.auto.AutoExample4;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

@Configuration
public class AutoTest implements ApplicationContextAware {

    private static final Logger LOGGER = LoggerFactory.getLogger(AutoTest.class);
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
        try {
            Object autoExample = applicationContext.getBean(AutoExample.class);
            if (Objects.nonNull(autoExample)) LOGGER.info("测试AutoExample是否注册到IOC容器");
            Object autoExample2 = applicationContext.getBean(AutoExample2.class);
            if (Objects.nonNull(autoExample2)) LOGGER.info("测试AutoExample2是否注册到IOC容器");
            Object autoExample3 = applicationContext.getBean(AutoExample3.class);
            if (Objects.nonNull(autoExample3)) LOGGER.info("测试AutoExample3是否注册到IOC容器");
            Object autoExample4 = applicationContext.getBean(AutoExample4.class);
            if (Objects.nonNull(autoExample4)) LOGGER.info("测试AutoExample4是否注册到IOC容器");
        } catch (Exception e) {

        }
    }
}
